package com.xiaocg.proxy.jdk;

import com.xiaocg.proxy.sta.SellTickets;
import com.xiaocg.proxy.sta.TrainStation;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

    private TrainStation station = new TrainStation();

    public SellTickets getProxyObject(){

        return (SellTickets) Proxy.newProxyInstance(station.getClass().getClassLoader(), station.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object invoke = method.invoke(station, args);
                return invoke;
            }
        });
    }

}
